<cfscript>    
    view = createObject("component", session.rootDir & ".views.layout");
    if( Session.Auth EQ True and (Session.strAuthType EQ Session.IT or Session.strAuthType EQ Session.HR) ){
        view.init("Step 6: Facilities - Access Control Update",
            "/jquery/ui-1.8.5/jquery-ui.min.js,/jquery/plugins/scrollTo/jquery.scrollTo-1.4.2-min.js, /" & session.rootDir & "/static/js/NonSCF/Step6-AccessControl.js",
            "/jquery/ui-1.8.5/themes/cupertino/jquery-ui.css","Home",main);
    }else{
        view.init("Denied","","","Home","Denied");
    }    
    view.html();
</cfscript>

<cffunction name="main" access="public" output="true" returntype="any">
    <cfscript>
        import models.*;
        KronosQueries = CreateObject("component", session.rootDir & ".DatabaseQueries.Kronos");
        AccessControlQueries = CreateObject("component", session.rootDir & ".DatabaseQueries.AccessControl");
        if( isDefined('URL.StepID') ){
            StepActions = ORMExecuteQuery("FROM StepActions WHERE StepActionsID = " & URL.StepID & " AND ActTimeStamp IS NULL");
        }else{
            StepActions = ORMExecuteQuery("FROM StepActions WHERE StepsID = 7 AND ActTimeStamp IS NULL AND TermReqID IS NULL");
            param default="-1" name="url.StepID";
        }
        FormAction = "../Controller/SubmitHandler.cfm?NonSCFStep6=update";
    </cfscript>
    <h1 class="title">Step 6: Facilities - Access Control Update</h1>
    <div class="entry">
        <cfform name="frmStep6" method="post" action="#FormAction#">        
            <p>
            Welcome, #Session.EmpInfo.FirstName# #Session.EmpInfo.LastName#.  
            In this step, provide the Access Control IDs as determined when 
            they are added to Access Control.
            </p>

            <cfinput type="hidden" name="StepID" value="#URL.StepID#" />    
            <table width = 100%>
                <tr>
                    <td colspan="3"><span class="tableHeader">Access Control Creation Report</span></td>
                    <td align="right" ><a href="PrintFinanceReport.cfm?SCF=1" target="_blank">Print Report</a></td>
                </tr>
            </table>
            
            <table width=100%>
                <tr> 
                    <td valign="top"><strong><u>Name, Job Title, &amp;<br /> Department (Badge)</u></strong></td>
                    <td valign="top"><strong><u>Access Level(s)<br /> Requested</u></strong></td>
                    <td valign="top"><strong><u>New Access <br />Control ID</u></u></strong></td>
                    <td valign="top"><strong><u>Comments</u></u></strong></td>
                </tr>
                
                <cftry>
                    <cfloop from="1" to="#ArrayLen(StepActions)#" index="i">
                        <cfset Employee = ORMExecuteQuery("FROM Employee WHERE EmployeeID = " & StepActions[i].getEmployeeID() & " AND NonSCFTypeID IS NOT NULL") />
                        <cfif ArrayLen(Employee) NEQ 0>                         
                            <cfset BadgeNumber = EntityLoad("Badges", Employee[1].getRosettaID()) />
                            <cfset PositionInfo = KronosQueries.funcGetPositionInfo(Employee[1].getPositionID()) />
                            <cfset Depts = KronosQueries.funcGetDepts(Employee[1].getDepartmentID()) />
                            <cfset AccessLevel = Employee[1].getBadgeAccessLevelID() EQ "-- None --" ? AccessControlQueries.funcGetAccess(0) : AccessControlQueries.funcGetAccess(Employee[1].getBadgeAccessLevelID()) />
                            <tbody id="#StepActions[i].getStepActionsID()#" class="AccessID">
                                <tr> 
                                    <td nowrap="nowrap" valign="top">#Employee[1].getFirstName()# #Employee[1].getLastName()# (#BadgeNumber[1].getBadgeNumber()#)</td>
                                    <td valign="top">
                                        <cfif AccessLevel.RecordCount GT 0>
                                            <cfloop query="AccessLevel">
                                                #AccessLevel.currentRow#) #AccessLevel.Descript#<BR />
                                            </cfloop>
                                        <cfelse>
                                            None
                                        </cfif>
                                    </td>
                                    <td valign="top">
                                        <cfinput type="text" name="AccessID" error_message="The Access Control ID for '#Employee[1].getFirstName()# #Employee[1].getLastName()#' 
                                            is required and must be numeric.  If there are no levels granted, and<br /> therefore 
                                            an Access Control record is not necessary, please leave this field blank."/>
                                        <cfinput type="hidden" name="RosettaID" value="#Employee[1].getRosettaID()#" />
                                    </td>
                                    <td valign="top"><cfinput type="text" name="comments" /></td>                        
                                </tr>
                            </tbody>
                        </cfif>
                    </cfloop>                
                <cfcatch type="Any" >
                </cfcatch>
                </cftry>

                <tr>
                    <td colspan="4">&nbsp;</td>
                </tr>
                <tr>
                    <td colspan="4" align="right">
                        <cfinput type="hidden" name="FormIndicator" value="0">
                        <cfinput type="hidden" name="FormAction" value="#FormAction#">
                        <cfinput type="button" name="Submit" value="Submit">
                    </td> 
                </tr>
            </table>            
        </cfform>
    </div>        

</cffunction>